package com.qianyu.project.core.api;

import com.qianyu.project.core.service.IFormService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author gs
 * @date create in 2020/12/11 18:11
 */
@Api(tags = "审批单管理接口")
@RestController
@RequestMapping("/forms")
public class FormController {

    @Autowired
    private IFormService formService;

    @ApiOperation("查询审批单")
    @GetMapping
    public Result findAll() {
        return ResultTool.success(formService.getByUserRole());
    }

    @ApiOperation("查询审批详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fid", value = "审批单id")
    })
    @GetMapping("/details/{fid}")
    public Result renderDetails(@PathVariable Integer fid) {
        return ResultTool.success(formService.renderTarget(fid));
    }

    @ApiOperation("依据用户查询审批详情")
    @GetMapping("/user")
    public Result findByUser() {
        return ResultTool.success(formService.getByUser());
    }

    @GetMapping("/dbds")
    public Result selectMybacklog(@RequestParam Map<String, String> params) {
        return ResultTool.success(formService.selectMybacklog(params));
    }

    @GetMapping("/zhuyedeshenqing")
    public Result zhuyedeshenqing() {
        return ResultTool.success(formService.zhuyedeshenqing());
    }

    @DeleteMapping("/{fid}")
    public Result remove(@PathVariable String fid) {
        formService.removeById(fid);
        return ResultTool.success();
    }
}
